package com.yyxk.thousandtime.util;

import java.util.Calendar;

/**
 * Created by liubin on 2017/5/10.
 */

public class TimeFormatUtil {

    /**
     * 毫秒转化时分显示
     */
    public static String formatTime(Long ms) {

        int ss = 1000;
        int mi = ss * 60;
        int hh = mi * 60;

        long hour = ms / hh;
        long minute = (ms - hour * hh) / mi;

        StringBuilder sb = new StringBuilder();

        if (hour > 0) {
            sb.append(hour + "小时");
        }
        if (minute > 0) {
            sb.append(minute + "分");
        }
        return sb.toString();
    }

    public static String formatBirthday(Long ms) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(ms);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        StringBuilder builder = new StringBuilder();
        if (year > 1970 && year - 1970 > 0) {
            builder.append(year - 1970).append("岁");
        }
        if (month > Calendar.JANUARY && month - Calendar.JANUARY > 0) {
            builder.append(month - Calendar.JANUARY).append("个月");
        }
//        System.out.print("day:" + day);
//        System.out.print("month:" + month);
//        System.out.print("year:" + year);
        if (day > 1) {
            builder.append(day - 1).append("天");
        } else {
            builder.append("1天");
        }
        return builder.toString();
    }

    public static void main(String[] args) {
        String birthday = formatBirthday(94846416000l);//3岁
        System.out.print("birthday:" + birthday);

        System.out.print("time:" + (1496392841000l + 12 * 60 * 1000));
    }

}
